#include "led.h"
#include "reg.h"
volatile int i = 0x30313233;

void led_delay(uint32_t delay)
{
 
  for (i = 6; i < delay; i++)
  {
    asm("NOP");
  }
}

// PA4 低电平亮
#define LED_ON() GPIOA->BCR = 1 << 4   // PA4 set
#define LED_OFF() GPIOA->BSHR = 1 << 4 // PA4 reset

void led_init()
{
  // 使能APB2 PA 时钟
  RCC->APB2PCENR |= 1 << 2;

  // mode4[0:1] 
  GPIOA->CFGLR |= (0x03 << (4 * 4)); //   00：通用推挽输出模式  

  // cfn4[2:3]
  GPIOA->CFGLR &= ~(0x03 << (4 * 4 + 2)); //  11：输出模式，最大速度 50MHz  

  LED_ON();
}

void led_flash_loop()
{
  led_init();
  while (1)
  {

    LED_ON();
    led_delay(50000);
    LED_OFF();
    led_delay(50000);

    LED_ON();
    led_delay(50000);
    LED_OFF();
    led_delay(50000);

    led_delay(700000);
  }
}
